const path = require("path");

const appDirectory = path.resolve(__filename, "../");

module.exports = {
  entry:  appDirectory+"/src/js/main.js",
  output: {
    path: appDirectory + "/dist",
    filename: "bundle.js",

    // publicPath: appDirectory +'/dist/', // 如果图片资源 和  index.html 不在一起，需要配置
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.less$/,
        use: [{
            loader: "style-loader" // creates style nodes from JS strings
        }, {
            loader: "css-loader" // translates CSS into CommonJS
        }, {
            loader: "less-loader" // compiles Less to CSS
        }]
      },
      {
        test: /\.(png|jpg|gif|jpeg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 71,
              name: 'images/[name]_[hash:5].[ext]',
            },
          }
        ]
      },
      {
        test: /\.(png|jpg|gif|jpeg)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'images/[name]_[hash:10].[ext]', //默认 32位hash值（哈希）
            }
          }
        ]
      },
      {// 讲解的很好：https://www.cnblogs.com/QianDingwei/p/10800795.html
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/, //排除
        use: {
          loader: 'babel-loader',
          options: {
            // presets: ['@babel/preset-env'] //目前还没有用到
            presets: ['es2015']
          }
        }
      }
    ]
  }
};
